package com.qmctl.rest.dao.merchsync;

import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;


@Repository
@Transactional
public class MerchItemDao {
    private SessionFactory sessionFactory;
    @Autowired
    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    } 

   /* public String doAddMerch(MerchItemEntity me){
    	String errcode="0";
    	Session s =  sessionFactory.getCurrentSession();
     	String queryString="select * from t_merchItemInfo where warehouseCode='"+me.getWarehouseCode()+"' and ownerCode='"+me.getOwnerCode()+"' and itemCode='"+me.getItemCode()+"'";

    	try{
      	  SQLQuery query = s.createSQLQuery(queryString);
      	  if(query.list().size()>0)
  		    s.save(me);
      	  else
      	   errcode="err.merchadded";
    	}
    	catch(Exception e){
    		errcode = "sqlerror.merchadd";
    		return errcode;
    	}
    	return errcode; 
    }
    public String doUpdateMerch(MerchItemEntity me){
    	String errcode="0";
    	Session s =  sessionFactory.getCurrentSession();
     	String queryString="select * from t_merchItemInfo where warehouseCode='"+me.getWarehouseCode()+"' and ownerCode='"+me.getOwnerCode()+"' and itemCode='"+me.getItemCode()+"'";

    	try{
      	  SQLQuery query = s.createSQLQuery(queryString);
      	  if(query.list().size()>0)
  		    s.save(me);
      	  else
      	   errcode="err.nomerch.update";
    	}
    	catch(Exception e){
    		errcode = "sqlerror.merchupdate";
    		return errcode;
    	}
    	return errcode;  	   	
    }*/
}
